<template>
   <div class="box">
    <div class="top">
        <div>
            <el-select v-model="value" placeholder="请选择" @change="handleChange">
                <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
                </el-option>
            </el-select>
        </div>
        <div class="search">
            <el-input v-model="params.keyword" placeholder="请输入内容"></el-input>
            <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
            <el-button type="primary" @click="handleConcel">取消筛选</el-button>
        </div>
    </div>
    <div class="bottom">
        <el-table
            :data="tableData"
            stripe
            style="width: 100%">
            <el-table-column
            prop="username"
            label="发布者"
            width="180">
            </el-table-column>
            <el-table-column
            prop="title"
            label="题目"
            width="180">
            </el-table-column>
            <el-table-column
            prop="type"
            label="类型"
            >
            </el-table-column>
            <el-table-column
            prop="publishtime"
            label="发布时间"
            width="180">
            </el-table-column>
            <el-table-column
            prop="agree"
            label="获赞数"
            width="180">
            </el-table-column>
            <el-table-column
            fixed="right"
            label="操作"
            width="180">
            <template slot-scope="scope">
                <!-- <el-button type="text" size="small" @click="handleClick(scope.row)">
                    删除
                </el-button> -->
                <el-popconfirm
                title="确定删除吗？"
                @confirm="handleClick(scope.row)"
                >
                    <el-button slot="reference">删除</el-button>
                </el-popconfirm>
            </template>
            </el-table-column>
        </el-table>
        <!-- 分页器 -->
        <div class="block">
        <el-pagination
            layout="prev, pager, next"
            :current-page="pageInfo.pageNum"
            @current-change="handleCurrentChange"
            :page-size="pageInfo.pageSize"
            :hide-on-single-page="true"
            :total="pageInfo.total"
        >
        </el-pagination>
        </div>
    </div>
  </div>
</template>

<script>
import {SecretGet,SecretSearchKeyword,SecretSearchType,SecretDelete} from '@/request/api'
export default {
  name: 'Secret',
  data(){
    return{
        options: [{
          value: '线组搭配',
          label: '线组搭配'
        }, {
          value: '浮漂选取',
          label: '浮漂选取'
        }, {
          value: '钓点选取',
          label: '钓点选取'
        }, {
          value: '调漂技巧',
          label: '调漂技巧'
        }, {
          value: '其他',
          label: '其他'
        }],
        value: '',
        tableData:[],
        pageInfo:{},
        params:{
            pageNum:1,
            type:'',
            keyword:''
        },
        delParams:{
          id:null
        }
    }
  },
  methods:{
    async handleChange(value){
        this.params.type = value
        let res = await SecretSearchType(this.params)
        this.tableData = res.data.data.list
        this.pageInfo = res.data.data
    },
    async handleCurrentChange(index){
        this.params.pageNum = index
        let res = await SecretGet(this.params)
        this.tableData = res.data.data.list
        this.pageInfo = res.data.data
    },
   async handleSearch(){
      let res = await SecretSearchKeyword(this.params)
      this.tableData = res.data.data.list
      this.pageInfo = res.data.data
    },
    async handleConcel(){
      this.params.keyword = ''
      this.params.type = ''
      this.params.pageNum = 1
      this.value = ''
      let res = await SecretGet(this.params)
      this.tableData = res.data.data.list
      this.pageInfo = res.data.data
    },
    async handleClick(id){
      console.log("id",id.secretid)
      this.delParams.id = id.secretid
      let res =await SecretDelete(this.delParams)
      if(res.data.state == 200){
        // 刷新数据
        // this.params.pageNum = 1
        let res = await SecretGet(this.params)
        this.tableData = res.data.data.list
        this.pageInfo = res.data.data
      }
    }
  },
  async created(){
    let res = await SecretGet(this.params)
    this.tableData = res.data.data.list
    this.pageInfo = res.data.data
  }
}
</script>

<style scoped>
.box{
    padding: 10px;
    width: 100%;
}
.top{
    display: flex;
    flex-direction: row;
    justify-content: flex-end;
    height: 40px;
    line-height: 40px;
    width: 100%;
}
.search{
    display: flex;
    flex-direction: row;
    margin-right: 10px;
    margin-left: 10px;
}
.block{
    text-align: center;
    margin-top: 20px;   
}
</style>
